<?php

declare(strict_types=1);

namespace App\Game\Logic\Sign;

use App\Game\Core\AStrategy;
use App\Game\Core\Packet;

/**
 *  心跳处理.
 */
class SignIn extends AStrategy
{
    /**
     * 执行方法.
     */
    public function exec()
    {
        $begin_time = isset($this->_params['data']['time']) ? $this->_params['data']['time'] : 0;
        $end_time = $this->getMillisecond();
        $time = $end_time - $begin_time;
        // 取类名作为事件名
        $classNameParts = explode('\\', __CLASS__);
        $event = end($classNameParts);
        return Packet::event($event);
    }

    public function getMillisecond()
    {
        [$t1, $t2] = explode(' ', microtime());
        return (float) sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
    }
}
